import { _decorator, Button, Component, instantiate, Label, Node, Prefab, resources } from 'cc';
import BaseView from '../../../platform/ui/BaseView';
import { Menu_Btns, ViewLayerDefine } from '../../common/enums';
import { ResManager } from '../../../platform/resources/ResMgr';
import { bind, uiview } from '../../../platform/ui/UIDecorator';
import { watch } from '@vue/reactivity';
import { LogMgr } from '../../../platform/log/LogMgr';
import { TbRoot } from '../../../platform/excel_table/TbRoot';
import { Tb_GameList, Tb_GameListContainer } from '../../tb/Tb_GameList';
import UIMgr from '../../../platform/ui/UIMgr';
import { GameLevel } from './GameLevel';
import { PlayerData } from '../../data/player/PlayerData';
const { ccclass, property } = _decorator;





@uiview({
    prefabPath:"prefab/ui/game/GameView",
    layer:ViewLayerDefine.Pop,
    single:true
})
@ccclass('GameView')
export class GameView extends BaseView<null,null> {
    @bind(Label)
    title:Label = null

    @bind(Node)
    back:Node = null
    @bind(Node)
    rank:Node = null
    @bind(Node)
    achivement:Node = null
    @bind(Node)
    levels:Node = null
    @bind(Node)
    chat:Node = null

    cfg:Tb_GameList = null

    protected init(): void {
        this.useAnimation = false
        this.initBtns()//按钮事件
    }
    initLevels() {
        let levels = this.cfg.levels
        let children = this.levels.children
        for (let index = 0; index < children.length; index++) {
            if(index >= levels.length){
                children[index].active = false
                continue
            }
            let child = children[index];
            child.active = true
            let level = child.getComponent(GameLevel)
            if(!level){
                level = child.addComponent(GameLevel)
            }
            this.registerComponent(level,this)
            level.init(index)
        }
    }
    initBtns() {
        this.back.on(Button.EventType.CLICK, this.onBackClick, this)
        this.rank.on(Button.EventType.CLICK, this.onRankClick, this)
        this.achivement.on(Button.EventType.CLICK, this.onAchivementClick, this)
        this.chat.on(Button.EventType.CLICK, this.onChatClick, this)
    }
    protected show(): void {
        this.cfg = this.showArgs[0]
        this.title.string = this.cfg.name
        this.initLevels()
    }
    onBackClick(){
        UIMgr.ins.closeUI(GameView)
    }
    onRankClick(){
        LogMgr.info("点击了排行:"+this.cfg.name);
    }
    onAchivementClick(){
        LogMgr.info("点击了成就:"+this.cfg.name);
    }
    onChatClick(){
        LogMgr.info("点击了讨论:"+this.cfg.name);
    }
}



